﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;

namespace robotGUI
{
    public partial class battLevel : UserControl
    {
        int percent;
        public int Percent
        {
            get { return percent; }
            set { percent = value; drawBatt(); Refresh(); }
        }

        string extra;
        public string Extra
        {
            get { return extra; }
            set { extra = value; drawBatt(); Refresh(); }
        }


        public battLevel()
        {
            InitializeComponent();
            battPicture = new Bitmap(109, 21);
            battBackground = new Bitmap(Properties.Resources.batCtlBack);
            battBar = new Bitmap(Properties.Resources.batCtlBar);
            pictureBox1.Image = battPicture;
            extra = "";
        }

        Bitmap battBackground;
        Bitmap battBar;
        private void battLevel_Load(object sender, EventArgs e)
        {
            drawBatt();
        }

        Image battPicture;
        void drawBatt()
        {
            Graphics g = Graphics.FromImage(battPicture);
            int pct = percent;
            if (pct > 100) pct = 100;
            if (pct < 0) pct = 0;
            g.DrawImageUnscaled(battBackground, 0, 0);
            g.DrawImageUnscaledAndClipped(battBar, new Rectangle(5, 5, (int)(pct * (89f / 100f)), 11));
            g.Dispose();
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            string s = percent.ToString() + "%" + extra;
            SizeF bounds = g.MeasureString(s, SystemFonts.DefaultFont);
            float x = (this.Width - bounds.Width) / 2;
            float y = (this.Height - bounds.Height) / 2;
            Brush back = new SolidBrush(BackColor);
            g.DrawString(s, SystemFonts.DefaultFont, back, x-1, y-1);
            g.DrawString(s, SystemFonts.DefaultFont, back, x+1, y-1);
            g.DrawString(s, SystemFonts.DefaultFont, back, x+1, y+1);
            g.DrawString(s, SystemFonts.DefaultFont, back, x-1, y+1);

            g.DrawString(s, SystemFonts.DefaultFont, SystemBrushes.ControlText, x, y);
            back.Dispose();
        }

    }
}
